package org.wattdepot.simulation.oahugrid.strategy;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.wattdepot.simulation.oahugrid.main.batch.BatchSimulation;
import org.wattdepot.simulation.oahugrid.powerplant.PowerPlant;

/**
 * Represents a data point in the simulation data set. 
 * A data point has three values: a time, a power plant, and the number of MW being generated 
 * at that point in time.
 *  
 * @author Philip Johnson
 *
 */
public class SimulationEntry {
  
  private long time; 
  private PowerPlant plant;
  private int gridMW;
  private int overheadMW;
  
  /**
   * Create a simulation dataset entry.
   * @param time The time at which the data was generated.
   * @param plant The plant generating the power.
   * @param gridMW The amount of megawatts generated to be used for power.
   * @param overheadMW The amount of megawatts generated to be used to run the plant.
   */
  public SimulationEntry(long time, PowerPlant plant, int gridMW, int overheadMW) {
    this.time = time;
    this.plant = plant;
    this.gridMW = gridMW;
    this.overheadMW = overheadMW;
  }

  /**
   * Returns the time.
   * @return The time. 
   */
  public long getTime() {
    return this.time;
  }
  
  /**
   * Returns the power generated for the grid.
   * @return The megawatts. 
   */
  public int getGridMW() {
    return this.gridMW;
  }
  
  /**
   * Returns this entry as a string in CSV format: time,plant,megawatts.
   * @return The entry as a string.
   */
  public String getCsv() {
    SimpleDateFormat sdf = new SimpleDateFormat(BatchSimulation.DATE_FORMAT, Locale.US);
    String timestamp = sdf.format(new Date(this.time)); 
    return String.format("%s,%s,%d,%d,%s", timestamp, this.plant, this.gridMW, this.overheadMW,
        this.plant.getType());
  }
 
  /**
   * Returns the PowerPlant associated with this entry.
   * @return The PowerPlant. 
   */
  public PowerPlant getPlant() {
    return this.plant;
  }
}
